import React from 'react'
import { useNavigate } from 'react-router-dom'
import cookie from 'react-cookies'

class AuthRouter extends React.Component {
    constructor (props) {
        super(props)
    }

    render () {
        // 判断是否有没有登陆
        const AuthLogin = () => {
            let navigate = useNavigate()
            React.useEffect(() => {
                var LoginUser = cookie.load('LoginUser') ? cookie.load('LoginUser') : {}
                if (JSON.stringify(LoginUser) == '{}') {
                    navigate('/user/base/login')
                }
            })
            return false
        }

        return (
            <>
                {this.props.auth && <AuthLogin />}
                {this.props.component}
            </>
        )
    }
}

export default AuthRouter;